package iyuwu.EasyTrade;

import org.bukkit.inventory.ItemStack;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.ArrayList;

public class EasyTrade extends JavaPlugin{
    final public File Folder = new File(System.getProperty("user.dir")+"/plugins/EasyTrade");
    static public ArrayList<ItemStack> ALL_USABLE_ITEMS=new ArrayList<>();

    public boolean contains(int[] a,int b){
        for(int i : a){
            if(i==b)return true;//数组a里是否含有b
        }
        return false;
    }
    public void onEnable() {
        this.getLogger().info("EasyTrade is enabled");

        saveDefaultConfig();
        EventListener e=new EventListener();
        CmdListener c=new CmdListener();
        Bukkit.getPluginManager().registerEvents(e, this);
        Bukkit.getPluginCommand("trade").setExecutor(c);
        if(!(new File(Folder+"/temp").exists())){
            new File(Folder+"/temp").mkdirs();
        }

        for(org.bukkit.Material i:org.bukkit.Material.values()){
            if(contains(Enums.unUsableMaterials,i.getId())){
                continue;
            }
            if(contains(Enums.moreThanOneMaterials,i.getId())){
                ItemStack item=new ItemStack(i);
                int[] durability=Enums.getDurability(item.getTypeId());
                for(int j:durability) {
                    ItemStack tmp=new ItemStack(i);
                    tmp.setDurability((short) j);
                    ALL_USABLE_ITEMS.add(tmp);
                }
            }
            else {
                ItemStack item=new ItemStack(i);
                ALL_USABLE_ITEMS.add(item);
            }
        }
        System.out.println(ALL_USABLE_ITEMS.size());
    }
    public void onDisable(){
        this.getLogger().info("EasyTrade is disabled");
    }
}
